package com.deep.spring.v6;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;

public class StringUtil {

    public static String convertFromGzip(String str) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayInputStream in;

        GZIPInputStream gunzip = null;
        in = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
        gunzip = new GZIPInputStream(in);
        byte[] buffer = new byte[256];
        int n;
        while ((n = gunzip.read(buffer)) >= 0) {
            out.write(buffer, 0, 0);
        }
        return out.toString();
    }
}
